package com.krystal.bean;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

/**
 * @author Krystal1
 * @date 2021/4/26 -13:32
 * 封装响应给前端的json数据的JavaBean（Controller会将JavaBean转为Json，前端要求该json中有data字段）
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class Result {
    private Object data;
    private Integer code;
    private String message;

    public static Result success(Object data){
        Result result = new Result();
        result.setCode(200);
        result.setMessage("success");
        result.setData(data);
        return result;
    }

    public static Result fail(){
        Result result = new Result();
        result.setCode(500);
        result.setMessage("fail");
        result.setData(null);
        return result;
    }
}
